package Word_Frequency;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class FileLoader {

    // 公共方法：读取文件并返回格式化的字符串
    public static String Array(String filePath) {
        StringBuilder result = new StringBuilder();

        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = br.readLine()) != null) {
                // 分割行，假设以空格分隔
                String[] parts = line.split("\\s+");
                if (parts.length == 2) {
                    String country = parts[0];
                    String number = parts[1];

                    // 拼接结果
                    if (result.length() > 0) {
                        result.append(", ");
                    }
                    result.append(country).append(":").append(number);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return result.toString();
    }
}